package com.kk.base.controller.admin;

import com.kk.base.bean.CodeMsg;
import com.kk.base.bean.PageBean;
import com.kk.base.bean.Result;
import com.kk.base.entity.home.Complaint;
import com.kk.base.service.home.ComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @info : 投诉控制层
 */
@RequestMapping("/admin/complaint")
@Controller
public class ComplaintController {

    @Autowired
    private ComplaintService complaintService;



    /**
     * 分页搜索投诉列表
     * @param model
     * @param complaint
     * @param pageBean
     * @return
     */
    @RequestMapping(value="/list")
    public String list(Model model, Complaint complaint, PageBean<Complaint> pageBean){
        model.addAttribute("title", "投诉列表");
        model.addAttribute("waybillNumber", complaint.getWaybillNumber());
        model.addAttribute("pageBean", complaintService.findList(complaint, pageBean));
        return "admin/complaint/list";
    }


    @RequestMapping(value="/accepted",method= RequestMethod.POST)
    @ResponseBody
    public Result<Boolean> accepted(@RequestParam(name="id")Long id){
        Complaint complaint = complaintService.find(id);
        complaint.setStatus(Complaint.ACCEPTED);
        if (complaintService.save(complaint) == null){
            return Result.error(CodeMsg.COMPLAINT_ACCEPTED_ERROR);
        }
        return Result.success(true);
    }




}
